<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="com.mysql.jdbc.Driver"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<%
String useridMessage=null;
String pwMessage=null;
String userid=null;
String pw1=null;
String pw2=null;
String email=null;

if (request.getParameter("userid") !=null){
	 userid = request.getParameter("userid");
	 pw1 = request.getParameter("pw1");
	 pw2 = request.getParameter("pw2");
	 email = request.getParameter("email");
	boolean valid = true;
	
	if (userid.length() <4 || userid.length()>20){
		valid = false;
		useridMessage = "使用者帳號長度不符";
	}
	if (!pw1.equals(pw2)){
		valid = false;
		pwMessage = "二次密碼不相符";
	}
	if (email.indexOf("@")== -1) {
		valid = false;
	}
	if (valid) {
		//1
		DriverManager.registerDriver(new Driver());
		// old connect
		// Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection("jdbc:mysql://j.snpy.org/j102","jstu","abc123");
		Statement stmt = conn.createStatement();
		String sq1 = "Insert into users (id,password,email) values ('"+userid+"','"+pw1+"','"+email+"')";
			System.out.println(sq1);
		int rowCount = stmt.executeUpdate(sq1);
		    System.out.println(rowCount);
	}
}



%>







<body>
<form action="" >
<table border=1 align=center width=600>
<tr>
<td align=center>帳號(*):</td>
<td><input name="userid" type="text" value="<%=userid==null? "": userid%>" /><%=useridMessage==null? "": useridMessage %></td>

</tr>
<tr>
<td align=center> 密碼(*):</td>
                                   
<td><input name="pw1" type="text" value="<%=pw1==null? "": pw1 %>" /><%=pwMessage==null? "": pwMessage %></td>
</tr>
<tr>
<td align=center>密碼:</td>
<td><input name="pw2" type="text" value="<%=pw2==null? "": pw2 %>"/></td>

</tr>
<tr>
<td align=center>E-mail(*):</td>
<td><input name="email" type="text" value="<%=email==null? "": email %>" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="註冊"/></td>
</tr>
</table>
</form>
</body>
</html>